// 用户认证相关工具函数

// 检查是否已登录
export const isLoggedIn = () => {
	const token = uni.getStorageSync('token')
	return !!token
}

// 获取用户ID
export const getUserId = () => {
	return uni.getStorageSync('userId')
}

// 获取用户信息
export const getUserInfo = () => {
	return uni.getStorageSync('userInfo')
}

// 获取token
export const getToken = () => {
	return uni.getStorageSync('token')
}

// 保存登录信息
export const saveLoginInfo = (loginData) => {
	const { userId, userInfo, token } = loginData
	
	if (userId) {
		uni.setStorageSync('userId', userId)
	}
	
	if (userInfo) {
		uni.setStorageSync('userInfo', userInfo)
	}
	
	if (token) {
		uni.setStorageSync('token', token)
	}
}

// 清除登录信息
export const clearLoginInfo = () => {
	uni.removeStorageSync('userId')
	uni.removeStorageSync('userInfo')
	uni.removeStorageSync('token')
}

// 跳转到登录页
export const goToLogin = () => {
	uni.reLaunch({
		url: '/pages/login/login'
	})
}

// 跳转到首页
export const goToHome = () => {
	uni.switchTab({
		url: '/pages/index/index'
	})
}

 